package br.foton.la.agenda.util;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

@SuppressWarnings("deprecation")
public class HibernateUtil {
	private static final SessionFactory factory;
	static{
		try {
			factory = new Configuration().configure().buildSessionFactory();
		} catch (Throwable e) {
			throw new ExceptionInInitializerError(e);
		}
	}
	
	public static Session getSession() throws HibernateException{
		return factory.openSession();
	}
	
	public void close(){
		if(getSession()!= null && getSession().isOpen()){
			getSession().close();
		}
	}
}
